<meta charset="utf-8">
<style>
table{
  border-collapse:collapse;
}
td{
  text-align:right;
  padding:10px;
}
td:hover{
  background:orange;
  color:red;
}
</style>
<script>
//打印出万年历
//打印出2018的日历
//打印出2018年一月日历
//打印出2018年二月日历


function getPrevMonthDayCount(){
  var now = new Date();
  var y = now.getFullYear();
  var m = now.getMonth()+1;
  if(m>=2){
    return getMonthDayCount(y,m-1);
  }else{
    return getMonthDayCount(y-1,12);
  }
}

function getMonthDayCount(year,month){
  var now = new Date();
  var y = year||now.getFullYear();
  var m = month||now.getMonth()+1;

  var dcount = 31;
  if(m==4||m==6||m==9||m==11){
    dcount = 30;
  }else if(m==2){
    if(y%4==0&&y%100!=0||y%400==0){
      dcount = 29;
    }else{
      dcount = 28;
    }
  }

  return dcount;
}

var w = 5;//201年1月1日是星期五


for(var t=2010;t<=2018;t++){

document.write("<h2 style='clear:both'>"+t+"年</h2>");

for(var k=1;k<=12;k++){

document.write("<table border=\"1\" style='float:left;margin:10px;'>");
document.write("<tr><td colspan='7'><h3>"+t+"年"+k+"月</h3></td></tr>");
document.write("<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>");

for(var i=1;i<=6;i++){
  document.write("<tr>");
  for(var j=1;j<=7;j++){
    document.write("<td>");
    var d = j+(i-1)*7-(w==0?7:w);
    if(d<1){
      if(k-1<=0){
        d += getMonthDayCount(t-1,12);//上一个月的天数
      }else{
        d += getMonthDayCount(t,k-1);//上一个月的天数
      }
    }else if(d>getMonthDayCount(t,k)){//本月的天数
      d -= getMonthDayCount(t,k);
    }
    document.write(d);
    
    document.write("</td>");
  }
  document.write("</tr>");
}

document.write("</table>");
//4


w = getMonthDayCount(t,k)%7+w%7;

if(w>=7) w = w -7;

console.log(w);


}



}



</script>





































